#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include "test.h"
#include "U_cv.h"
#include <fstream>

using namespace std;

float ray_25[9] = {
154.331,
120.113,
252.167,
253.102,
-0.0602018,
0.609923,
0,
0,
0,
};
void saveMatToCSV(const Mat& mat, const std::string& filename)
{
    // 打开输出文件
    std::ofstream outFile(filename);
    if (!outFile.is_open()) {
        std::cerr << "Failed to open output file: " << filename << std::endl;
        return;
    }


    // 确保mat是浮点型
    if (mat.type() != CV_32F) {
        std::cerr << "Matrix type is not CV_32F!" << std::endl;
        return;
    }

    // 获取矩阵的行数和列数
    int rows = mat.rows ;
    int cols = mat.cols ;

    // 按照行宽写入数据
    for (int i = 0; i < rows ; ++i) {
        for (int j = 0; j < (cols - 220); ++j) {
        // for (int j = 0; j < cols; ++j) {
		
            outFile << mat.at<float>(i, j); // 写入当前元素
            // if (j < cols - 1) {
            //     outFile << ","; // 不是最后一列则添加逗号
            // }
                outFile << ","; // 最后一列则添加逗号

        }
        outFile << endl; // 每行结束后换行
    }

    outFile.close();
    std::cout << "Data saved to CSV file: " << filename << std::endl;
}

int U_test(void)
{
    float data_in[76800] = {0};
    vector<Mat> view_depth;
    for (int i = 0; i < 76800; i++)
    {
        data_in[i] = 1;
    }
	Mat depth_arr = Mat(240,320,CV_32F,data_in);
	Mat ray_arr = Mat(9,1,CV_32F,ray_25);
    s1_ray_to_xy(depth_arr,ray_arr);
    saveMatToCSV(depth_arr, "ray_out.csv");
    return 0;
}



int main(int argc, char const *argv[])
{
//     int myNumbers[5] = {0};
// cout << myNumbers[3];
    // test();
    // mul();
    // U_test();
    version_print();
    lens_new();

    return 0;
}





/*
camke .
make 
./main
*/

